<%-- 
    Document   : success
    Created on : 24-abr-2014, 12:06:16
    Author     : Rafa
--%>

<%@page import="java.util.Arrays"%>
<%@page import="java.util.Set"%>
<%@page import="clases.Seccion"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE html>
<html>
    <head>
        <%@include file="head.html" %>

        <script src="amcharts/amcharts.js" type="text/javascript"></script>
        <script src="amcharts/serial.js" type="text/javascript"></script>
        <script src="amcharts/exporting/amexport.js" type="text/javascript"></script>
        <script src="amcharts/exporting/rgbcolor.js" type="text/javascript"></script>
        <script src="amcharts/exporting/canvg.js" type="text/javascript"></script>
        <script src="amcharts/exporting/filesaver.js" type="text/javascript"></script>
        <script src="amcharts/exporting/jspdf.js" type="text/javascript"></script>
        <script src="amcharts/exporting/jspdf.plugin.addimage.js" type="text/javascript"></script>

        <logic:empty name="ModificarInicioSuperuserActionForm" property="error">  
            <%
                Set<Seccion> conjuntoTodasSecciones = (Set<Seccion>) request.getAttribute("listaTodasSecciones");
                Seccion[] listaTodasSecciones = conjuntoTodasSecciones.toArray(new Seccion[]{});

                List<Integer> listaNumTotalArtNuevos = (List<Integer>) request.getAttribute("listaNumTotalArtNuevos");
                List<Integer> listaNumTotalArtRevision = (List<Integer>) request.getAttribute("listaNumTotalArtRevision");
                List<Integer> listaNumTotalArtMaquetacion = (List<Integer>) request.getAttribute("listaNumTotalArtMaquetacion");
                List<Integer> listaNumTotalArtImprimir = (List<Integer>) request.getAttribute("listaNumTotalArtImprimir");

                String charDaNuevos = "[";
                String charDaRevision = "[";
                String charDaMaquetacion = "[";
                String charDaImprimir = "[";

                for (int i = 0; i < listaTodasSecciones.length; i++) {
                    charDaNuevos += "{";
                    charDaRevision += "{";
                    charDaMaquetacion += "{";
                    charDaImprimir += "{";

                    charDaNuevos += "'country':'" + listaTodasSecciones[i].getNombre() + "',";
                    charDaRevision += "'country':'" + listaTodasSecciones[i].getNombre() + "',";
                    charDaMaquetacion += "'country':'" + listaTodasSecciones[i].getNombre() + "',";
                    charDaImprimir += "'country':'" + listaTodasSecciones[i].getNombre() + "',";

                    charDaNuevos += "'visits':'" + listaNumTotalArtNuevos.get(i) + "'";
                    charDaRevision += "'visits':'" + listaNumTotalArtRevision.get(i) + "'";
                    charDaMaquetacion += "'visits':'" + listaNumTotalArtMaquetacion.get(i) + "'";
                    charDaImprimir += "'visits':'" + listaNumTotalArtImprimir.get(i) + "'";

                    if (i == listaTodasSecciones.length) {
                        charDaNuevos += "}";
                        charDaRevision += "}";
                        charDaMaquetacion += "}";
                        charDaImprimir += "}";
                    } else {
                        charDaNuevos += "},";
                        charDaRevision += "},";
                        charDaMaquetacion += "},";
                        charDaImprimir += "},";
                    }
                }
                charDaNuevos += "]";
                charDaRevision += "]";
                charDaMaquetacion += "]";
                charDaImprimir += "]";

                for (int i = 0; i < 4; i++) {
                    String charDa = "";
                    String nombre = "";
                    if (i == 0) {
                        nombre = "Articulos Nuevos";
                        charDa = charDaNuevos;
                    } else if (i == 1) {
                        nombre = "Articulos en Revision";
                        charDa = charDaRevision;
                    } else if (i == 2) {
                        nombre = "Articulos en Maquetacion";
                        charDa = charDaMaquetacion;
                    } else if (i == 3) {
                        nombre = "Articulos a Imprimir";
                        charDa = charDaImprimir;
                    }

            %>  

            <!-- Grafica -->
            <script type="text/javascript">
                AmCharts.ready(function() {
                    // SERIAL CHART
                    chart = new AmCharts.AmSerialChart();
                    chart.dataProvider = <%=charDa%>;
                    chart.categoryField = "country";
                    // the following two lines makes chart 3D
                    chart.depth3D = 20;
                    chart.angle = 30;

                    // AXES
                    // category
                    var categoryAxis = chart.categoryAxis;
                    categoryAxis.labelRotation = 90;
                    categoryAxis.dashLength = 5;
                    categoryAxis.gridPosition = "start";

                    // value
                    var valueAxis = new AmCharts.ValueAxis();
                    valueAxis.title = '<%=nombre%>';
                    valueAxis.dashLength = 5;
                    chart.addValueAxis(valueAxis);

                    // GRAPH
                    var graph = new AmCharts.AmGraph();
                    graph.valueField = "visits";
                    graph.colorField = "color";
                    graph.balloonText = "<span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>";
                    graph.type = "column";
                    graph.lineAlpha = 0;
                    graph.fillAlphas = 1;
                    chart.addGraph(graph);

                    // CURSOR
                    var chartCursor = new AmCharts.ChartCursor();
                    chartCursor.cursorAlpha = 0;
                    chartCursor.zoomable = false;
                    chartCursor.categoryBalloonEnabled = false;
                    chart.addChartCursor(chartCursor);

                    chart.creditsPosition = "top-right";

                    //EXPORT
                    chart.exportConfig = {
                        menuTop: "21px",
                        menuBottom: "auto",
                        menuRight: "21px",
                        backgroundColor: "#efefef",
                        menuItemStyle: {
                            backgroundColor: '#EFEFEF',
                            rollOverBackgroundColor: '#DDDDDD'},
                        menuItemOutput: {
                            fileName: '<%=nombre%>'
                        },
                        menuItems: [{
                                textAlign: 'center',
                                icon: 'http://www.amcharts.com/lib/3/images/export.png',
                                onclick: function() {
                                },
                                items: [{
                                        title: 'JPG',
                                        format: 'jpg'
                                    }, {
                                        title: 'PNG',
                                        format: 'png'
                                    }, {
                                        title: 'SVG',
                                        format: 'svg'
                                    }]
                            }]
                    };

                    // WRITE
                    chart.write("chartdiv" +<%=i%>);
                });
            </script>  
            <% }%>
        </logic:empty>
    </head>
    <body>
        <!-- Header -->
        <div id="header" class="skel-panels-fixed">

            <div class="top">

                <!-- Logo -->
                <%@include file="perfil.jsp" %>

                <!-- Nav -->
                <nav id="nav">
                    <ul>
                        <li><a href="#inicio" id="inicio-link" class="skel-panels-ignoreHref"><span class="fa fa-dashboard">Control de Mando</span></a></li>
                        <li><html:link action="/VistaUsuario/Superuser/irSecciones"><span class="fa fa-envelope-o">Secciones</span></html:link></li>
                        <li><html:link action="/VistaUsuario/Superuser/irUsuarios"><span class="fa fa-eye">Usuarios</span></html:link></li>
                        <li><html:link action="/VistaUsuario/Superuser/irAutoresSuperuser"><span class="fa fa-check-square">Autores</span></html:link></li>
                        <li><html:link action="/VistaUsuario/Superuser/irRevistas"><span class="fa fa-users">Revista</span></html:link></li>                
                        </ul>
                    </nav>

                </div>

            </div>
            <!-- Main -->
            <div id="main">

                <!-- Intro -->
                <section id="inicio" class="one">
                    <div class="container">

                        <!-- Errores -->
                    <logic:notEmpty name="ModificarInicioSuperuserActionForm" property="error">    
                        <bean:write name="ModificarInicioSuperuserActionForm" property="error" filter="false"/>
                    </logic:notEmpty>
                    <logic:empty name="ModificarInicioSuperuserActionForm" property="error"> 
                        <div id="datosEnNumeros" style="text-align: left">
                            <%
                                Integer numNuevos = (Integer) request.getAttribute("numTotalesNuevos");
                                Integer numRevision = (Integer) request.getAttribute("numTotalesRevision");
                                Integer numMaquetacion = (Integer) request.getAttribute("numTotalesMaquetacion");
                                Integer numImprimir = (Integer) request.getAttribute("numTotalesImprimir");
                                Integer numTotalSecciones = (Integer) request.getAttribute("numTotalSecciones");
                            %>
                            <p>Número de Secciones: <%=numTotalSecciones%></p>
                            <p>
                                Articulos Totales Nuevos: <%=numNuevos%><br />
                                Articulos Totales en Revision: <%=numRevision%><br />
                                Articulos Totales en Maquetacion: <%=numMaquetacion%><br />
                                Articulos Totales a Imprmir: <%=numImprimir%><br />

                            </p>
                        </div>

                        <div id="chartdiv0" style="width: auto; height: 300px;"></div>
                        <div id="chartdiv1" style="width: auto; height: 300px;"></div>
                        <div id="chartdiv2" style="width: auto; height: 300px;"></div>
                        <div id="chartdiv3" style="width: auto; height: 300px;"></div>
                    </logic:empty>                 
                </div>
            </section>

        </div>

        <!-- Footer -->
        <div id="footer">
            <%@include file="footer.html" %>
        </div>

    </body>
</html>
